//
//  WarLayer.h
//  DiceWar
//
//  Created by Xiao  Feng on 19/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef CLASSES_GAME_GAMEPLAY_WarLayer_H_
#define CLASSES_GAME_GAMEPLAY_WarLayer_H_

#include "cocos2d.h"
#include "HexMapLayer.h"
#include "FightingLayer.h"
#include "FightingAnimLayer.h"
#include "WarLayerState.h"
#include "PlayersManager.h"

class PlayerInfoLayer;

class WarLayer : public cocos2d::CCLayer
{
public:
    LAYER_NODE_FUNC(WarLayer);
    
    WarLayer();
    ~WarLayer();
    
    virtual void onEnter();
    virtual void registerWithTouchDispatcher();
    
    // default implements are used to call script callback if exist
    virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent);
    virtual void onEndTurnButtonClicked(CCObject* pSender);
    
public:
    bool init();
    void onCellClicked(int coordinateX, int coordinateY);
    
    virtual void onFightingAnimOver();
    
private:
    bool initLayers();
    bool initUserInterface();
    void setInitState();
    
    void startFightAnimation();
    cocos2d::CCTouch* getFirstTouchPoint(cocos2d::CCSet* pTouches);
    
private:
    friend class WarLayerState;
    friend class WarLayerStateWaitForAttacker;
    friend class WarLayerStateWaitForDefender;
    
    HexMapLayer* m_pMapLayer;
    FightingLayer* m_pFightingLayer;
    FightingAnimLayer* m_pFightingAnimLayer;
    PlayerInfoLayer* m_pPlayerInfoLayer;
    
    PlayersManager m_playersManager;
    WarLayerState m_state;
};
#endif //CLASSES_GAME_GAMEPLAY_WarLayer_H_
